package com.java.jvalidator.framework;

import java.util.Locale;
import java.util.ResourceBundle;

public class PropertyNameRetriever implements IPropertyNameRetriever {
	private static final String DEFAULT_PROPERTY_NAME_FILE = "property-name";
	private static final String SIGN = ".";

	public String retrieveName(Object obj, String propertyName) {
		return retrieveName(obj, propertyName, null);
	}

	public String retrieveName(Object obj, String propertyName, Locale locale) {
		if ((obj == null) || (propertyName == null)) {
			return null;
		}
		if (locale == null) {
			locale = Locale.getDefault();
		}
		ResourceBundle bundle = ResourceBundle.getBundle(DEFAULT_PROPERTY_NAME_FILE, locale);
		String className = obj.getClass().getName();
		String key = className + SIGN + propertyName;
		return bundle.getString(key);
	}
}
